package com.bustle.product;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;

import com.bustle.product.data.Product.ProductType;
import com.bustle.product.dto.product.ProductDto;
import com.bustle.product.dto.product.ProductDtoDao;

@Local
public interface ProductDtoManager
{

  public List<ProductDto> getListProduct();
  public ProductDto getById(int idProduct);
  public List<ProductType> getProductType();
  public List<ProductDto> getSearchProductTypeProvider(ProductType productType, Integer idProvider);
  public List<ProductDto> getSearchProductProductType(ProductType productType);
  public List<ProductDto> getSearchProductProvider(int idProvider);

  @Stateless
  public class DefaultProductManager implements ProductDtoManager
  {

    @EJB
    private ProductDtoDao productDtoDao;

    @Override
    public List<ProductDto> getListProduct()
    {
      return productDtoDao.retrieveAll();
    }

    @Override
    public List<ProductDto> getSearchProductTypeProvider(ProductType productType, Integer idProvider)
    {
      return productDtoDao.retrieveProductsDtoByTypeAndProvider(productType, idProvider);
    }

    @Override
    public List<ProductDto> getSearchProductProductType(ProductType productType)
    {
      return productDtoDao.retrieveProductsDtoByProductType(productType);
    }

    @Override
    public List<ProductDto> getSearchProductProvider(int idProvider)
    {
      return productDtoDao.retrieveProductsDtoByIdProvider(idProvider);
    }

    @Override
    public ProductDto getById(int idProduct)
    {
      return productDtoDao.retrieve(idProduct);
    }

    @Override
    public List<ProductType> getProductType()
    {
      ProductType[] productTypes = ProductType.values();
      List<ProductType> result = new ArrayList<ProductType>();
      for (ProductType pt : productTypes)
        result.add(pt);
      return result;
    }

    public DefaultProductManager()
    {
    }


  }

}
